using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Universe.Farm.Service.Mesages
{
    class MessageHeader
    {
        public string ComputerID;
        public TimeStamp Stamp;

        public MessageHeader(string computerID, TimeStamp stamp)
        {
            ComputerID = computerID;
            Stamp = stamp;
        }

        public static MessageHeader Parse(BinaryReader reader)
        {
            byte[] rawStamp = reader.ReadBytes(TimeStamp.Size);
            TimeStamp stamp = TimeStamp.Parse(rawStamp);
            string computer = reader.ReadString();
            return new MessageHeader(computer, stamp);
        }

        public void Serialize(BinaryWriter writer)
        {
            writer.Write(Stamp.Serialize());
            writer.Write(ComputerID);
        }
    }
}
